﻿#include <iostream>
#include <string>
using namespace std;
/* 对象创建型模式
1.意图：
提供一个创建一系列相关或相互依赖对象的接口，而无需指定它们具体的类。
2.别名：
Kit
3.适用性：
在以下情况可使用Abstract Factory模式：
a.一个系统要独立于它的产品的创建、组合和表示时
b.一个系统要由多个产品系列中的一个来配置时
c.当你要强调一系列相关的产品对象的设计以便进行联合使用时
d.当你提供一个产品类库，而只想显示它们的接口而不是实现时
4.效果：
优点：
a.它分离了具体的类
b.它使得易于交换产品系列
c.它有利于产品的一致性
缺点：
a.难以支持新种类的产品
*/
//抽象产品类
class Product
{
public:
	virtual void Show() = 0;
};
//抽象产品族
class KeyBoard :public Product {};
class Mouse :public Product {};
//具体产品
class LogiKeyBoard :public KeyBoard
{
public:
	void Show()
	{
		cout << "罗技键盘" << endl;
	}
};
class RazerKeyBoard :public KeyBoard
{
public:
	void Show()
	{
		cout << "雷蛇键盘" << endl;
	}

};
class LogiMouse :public Mouse
{
public:
	void Show()
	{
		cout << "罗技鼠标" << endl;
	}
};
class RazerMouse :public Mouse
{
public:
	void Show()
	{
		cout << "雷蛇鼠标" << endl;
	}
};
//抽象工厂
class Factory
{
public:
	virtual KeyBoard* CreateKeyBoard() = 0;
	virtual Mouse* CreateMouse() = 0;
};
//具体工厂
class LogiFactory :public Factory
{
public:
	KeyBoard* CreateKeyBoard()
	{
		return new LogiKeyBoard();
	}
	Mouse* CreateMouse()
	{
		return new LogiMouse();
	}
};
class RazerFactory :public Factory
{
public:
	KeyBoard* CreateKeyBoard()
	{
		return new RazerKeyBoard();
	}
	Mouse* CreateMouse()
	{
		return new RazerMouse();
	}
};
/*
int main()
{
	Factory* factory = new LogiFactory;
	KeyBoard* keyboard = factory->CreateKeyBoard();
	Mouse* mouse = factory->CreateMouse();
	keyboard->Show();
	mouse->Show();
	delete factory;
	delete keyboard;
	delete mouse;
	factory = new RazerFactory;
	keyboard = factory->CreateKeyBoard();
	mouse = factory->CreateMouse();
	keyboard->Show();
	mouse->Show();
	delete factory;
	delete keyboard;
	delete mouse;
	factory = nullptr;
	keyboard = nullptr;
	mouse = nullptr;
	return 0;
}
*/